package com.test08_面向对象应用;

import org.junit.Test;

public class YootkDemo_02 {

    @Test
    public void test1() {
        Person person = new Person("林有有", "北京-天安门");
        System.out.println(person);
    }

    @Test
    public void test2() {
        Person person = new Student("林有有", "北京-天安门", '女', 24, 68, 99);  // 向上转型
        System.out.println(person);
    }
}

class Person {
    private String name;
    private String addr;
    private char sex;
    private int age;

    public Person() {
    }

    public Person(String name, String addr) {
        this(name, addr, '男', 18);
    }

    public Person(String name, String addr, char sex, int age) {
        this.name = name;
        this.addr = addr;
        this.sex = sex;
        this.age = age;
    }

    @Override
    public String toString() {
        return "姓名：" + this.name + "、地址：" + this.addr + "、性别：" + this.sex + "、年龄：" + this.age;
    }
}

/**
 * 学生类
 */
class Student extends Person {
    private double math;
    private double english;

    public Student() {
    }

    public Student(String name, String addr) {
        super(name, addr);  // 调用父类中的双参构造
    }

    public Student(String name, String addr, char sex, int age, double math, double english) {
        super(name, addr, sex, age);    // super调用父类构造
        this.math = math;
        this.english = english;
    }

    @Override
    public String toString() {
        return super.toString() + "，数学成绩：" + this.math + "、英语成绩：" + this.english;
    }
}
